package 穷举;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2021/12/30
 * @description
 */
public class Demo01JZ74 {


    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
        int[] arrays = new int[101];
        for (int i = 1; i < arrays.length; i++) {
            arrays[i] = i;
        }
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();

        for (int i = 1; i < arrays.length; i++) {
            ArrayList<Integer> list = new ArrayList<>();
            int t = arrays[i];
            list.add(t);
            for (int j = i + 1; j < arrays.length; j++) {
                t += arrays[j];
                list.add(arrays[j]);
                if (t == sum) {
                    res.add(list);
                    break;
                } else if (t > sum) {
                    break;
                }
            }
        }
        return res;
    }
}
